<template>
  <div>
    <el-radio-group v-model="tabPosition" style="margin-bottom: 20px;">
      <el-radio-button label="overview">总览</el-radio-button>
      <!--<el-radio-button label="detail">详细</el-radio-button>-->
    </el-radio-group>
    <div v-show="tabPosition==='overview'">
      <el-table :data="overviewData" style="width: 100%;" height="500" :header-cell-style="headerCellStyle">
        <el-table-column prop="id" align="center" label="序号" width="150">
        </el-table-column>
        <el-table-column prop="name" align="center" label="抽奖名称" width="250">
        </el-table-column>
        <el-table-column prop="prizeName" align="center" label="抽奖奖品" width="250" :formatter="formatPrize">
        </el-table-column>
        <el-table-column prop="type" align="center" label="抽奖方式" width="250" :formatter="formatType">
        </el-table-column>
        <el-table-column prop="num" align="center" label="参与人数" width="200">
        </el-table-column>
        <el-table-column prop="winningCount" align="center" label="中奖人数" min-width="120">
        </el-table-column>
        <el-table-column prop="winningCount" align="center" label="中奖人数" min-width="120">
        </el-table-column>
        <el-table-column align="center" label="操作" min-width="120">
          <template slot-scope="scope">
            <el-button v-if="scope.row.status==35" type="text" size="mini" @click="results(scope.row)">开奖结果</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="toolbar" style="padding:10px;">
        <el-pagination
          @size-change="sizeChangeHandle"
          @current-change="currentChangeHandle"
          :current-page="pageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          :total="totalPage"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
    </div>
    <div v-show="tabPosition==='detail'">
      <el-form label-width="120px"  size="mini" :model="dataForm">
        <el-row>
          <el-col :span="6">
            <el-form-item label="抽奖名称：">
              <el-input v-model="dataForm.name" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="抽奖奖品：">
              <el-input v-model="dataForm.goodsName" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="抽奖时间：">
              <el-date-picker
                style="width: 100%"
                v-model="dataForm.time"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="会员账户：">
              <el-input v-model="dataForm.account" ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="抽奖方式：">
              <el-select v-model="dataForm.type" style="width: 100%" placeholder="请选择抽奖方式">
                <el-option label="全部" value=""></el-option>
                <el-option label="评论抽奖" value="0"></el-option>
                <el-option label="点赞抽奖" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖品形式：">
              <el-select v-model="dataForm.itemType" style="width: 100%" placeholder="请选择奖品形式">
                <el-option label="全部" value=""></el-option>
                <el-option label="优惠券" value="0"></el-option>
                <el-option label="实物" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item>
              <el-button type="primary" @click="searchInfo()">查询</el-button>
              <el-button @click="reset()">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <el-table :data="detailData" style="width: 100%" height="500" :header-cell-style="headerCellStyle">
        <el-table-column prop="id" align="center" label="序号" width="150">
        </el-table-column>
        <el-table-column prop="drawName" align="center" label="抽奖名称" width="250">
        </el-table-column>
        <el-table-column prop="prizeName" align="center" label="抽奖奖品" width="150" :formatter="prizename">
        </el-table-column>
        <el-table-column prop="type" align="center" label="抽奖方式" width="150" :formatter="formatType">
        </el-table-column>
        <el-table-column prop="prizeType" align="center" label="奖品类型" width="150" :formatter="formatPrizeType">
        </el-table-column>
        <el-table-column prop="userName" align="center" label="会员账户" width="150">
        </el-table-column>
        <el-table-column prop="address" align="center" label="收货地址" width="150">
        </el-table-column>
        <el-table-column prop="createTime" align="center" label="抽奖时间" min-width="150">
        </el-table-column>
      </el-table>
      <div class="toolbar" style="padding:10px;">
        <el-pagination
          @size-change="sizeChangeHandleInfo"
          @current-change="currentChangeHandleInfo"
          :current-page="InfopageIndex"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="InfopageSize"
          :total="InfototalPage"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
    </div>
    <el-dialog
      title="开奖结果"
      :visible.sync="resultsDialogVisible"
      width="80%"
      append-to-body>
      <div>
        <el-table :data="resultsTableData" style="width: 100%;margin-top: 15px;" height="300" :header-cell-style="headerCellStyle" :cell-style="cellStyle">
          <template slot="empty">
            <p>暂无数据</p>
          </template>
          <el-table-column prop="number" :show-overflow-tooltip="true" align="center" label="开奖编号" min-width="20%">
          </el-table-column>
          <el-table-column prop="prizeName" :show-overflow-tooltip="true" align="center" label="奖品名称" min-width="20%">
          </el-table-column>
          <el-table-column prop="consignee" :show-overflow-tooltip="true" align="center" label="收货人" min-width="20%">
          </el-table-column>
          <el-table-column prop="phone" :show-overflow-tooltip="true" align="center" label="收货人手机" min-width="20%">
          </el-table-column>
          <el-table-column prop="userName" :show-overflow-tooltip="true" align="center" label="用户名称" min-width="20%">
          </el-table-column>
          <el-table-column prop="prizeType" :show-overflow-tooltip="true" align="center" label="奖品类型" min-width="10%" :formatter="formatePrizeType">
          </el-table-column>
          <el-table-column prop="address" :show-overflow-tooltip="true" align="center" label="地址" min-width="20%">
          </el-table-column>
          <el-table-column prop="statusVal" :show-overflow-tooltip="true" align="center" label="状态" min-width="10%">
          </el-table-column>
        </el-table>
        <div style="padding: 15px;text-align: right;">
          <el-pagination
            layout="total, prev, pager, next, jumper,sizes"
            @current-change="refreshPageRequest3"
            :current-page="pageRequest3.pageNum"
            :page-size="pageRequest3.pageSize"
            :total="totalSize3"
            :page-sizes="[10, 20, 30, 40]"
            @size-change="handleSizeChange3"
          ></el-pagination>
        </div>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    name: "LiveInfoDataLottery",
    components: {
    },
    data() {
      return {
        headerCellStyle:{
          'background-color': '#f1f1f1'
        },
        cellStyle:{
          'font-size':'12px'
        },
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        InfopageIndex: 1,
        InfopageSize: 10,
        InfototalPage: 0,
        tabPosition:'overview',
        overviewData:[],
        detailData:[],
        dataForm:{
          name:'',
          goodsName:'',
          time:'',
          account:'',
          type:'',
          itemType:''
        },
        resultsDialogVisible: false,
        resultsTableData: [],
        pageRequest3:{
          pageNum:1,
          pageSize:10
        },
        totalSize3:0,
      }
    },
    mounted: function () {

    },
    methods: {
      reset(){
        this.dataForm = {}
      },
      searchInfo(){
        this.getdetailData();
      },
      getPData(row){
        this.liveId=row.id;
        this.getDataList()
        this.getdetailData()

      },
      getDataList() {
        let params={};
        params.pageNum=this.pageIndex;
        params.pageSize=this.pageSize;
        params.liveId=this.liveId;
        this.utils.request.liveRequest({
          url: '/api/v1/liveData/getLiveLuckDrawList',
          method:'get',
          params: params
        }).then(result => {
          let data = result.data;
          if (data && data.code == "0") {
            this.overviewData=data.data.rows;
            this.totalPage = data.data.total
          }
        })
      },
      getdetailData(){
        let params={};
        params.pageNum=this.InfopageIndex;
        params.pageSize=this.InfopageSize;
        params.liveId=this.liveId;
        params.name=this.dataForm.name;
        params.goodsName=this.dataForm.goodsName
        params.startTime=this.dataForm.time[0];
        params.endTime=this.dataForm.time[1];
        params.userName=this.dataForm.account;
        params.type=this.dataForm.type;
        params.prizeType=this.dataForm.itemType;
        this.utils.request.liveRequest({
          url: '/api/v1/liveData/getLiveDrawRecordList',
          method:'get',
          params: params
        }).then(result => {
          let data = result.data;
          if (data && data.code == "0") {

            this.detailData=data.data.rows;
            this.InfototalPage = data.data.total
          }
        })
      },
      // 每页数
      sizeChangeHandle(val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle(val) {
        this.pageIndex = val
        this.getDataList()
      },
      sizeChangeHandleInfo(val) {
        this.InfopageSize = val
        this.InfopageIndex = 1
        this.getdetailData()
      },
      // 当前页
      currentChangeHandleInfo(val) {
        this.InfopageIndex = val
        this.getdetailData()
      },
      formatPrize: function (row, column) {
        var prizeName='';
        if(row.prizeType===0){
          prizeName=row.couponName;
        }else {
          prizeName=row.goodsName;
        }

        return prizeName
      },
      formatType: function (row, column) {
        return row.type === 1 ? '评论' : row.type === 0 ? '点赞' : '未知'
      },
      prizename: function (row, column) {
        var prizeName='';
        if(row.prizeType===0){
          prizeName=row.couponName;
        }else{
          prizeName=row.prizeName;
        }
        return prizeName;
      },
      formatPrizeType: function (row, column) {
        if (row.prizeType===0){
          return '优惠卷'
        }else if (row.prizeType===1){
          return '实物'
        }else {
          return '积分'
        }
      },
      results(row){ // 开奖结果
        this.findPageDrawResult(row);
        this.resultsDialogVisible = true
      },
      //查看中奖结果
      findPageDrawResult(row){
        this.rowId3=row.id;
        let params={"drawId":row.id,"pageNum":this.pageRequest3.pageNum,"pageSize":this.pageRequest3.pageSize}
        let this_=this;
        this.utils.request.liveRequest({
          url: '/api/v1/broadcast/getLiveDrawRecordList',
          method: 'get',
          params: params
        }).then(result => {
          let data = result.data;
          if (data && data.code === '0') {
            this_.resultsTableData = data.data.rows;
            this.totalSize3 = data.data.total;
            this_.$forceUpdate();
          } else {
            this_.resultsTableData = []
            this_.totalSize3 = 0
          }
        });
      },
      formatePrizeType(row, column, cellValue, index) {
        //奖品类型  0 优惠券 1 实物 2 积分
        if (cellValue == '0') {
          return "优惠券";
        } else if (cellValue == '1') {
          return "实物";
        }else if (cellValue == '2') {
          return "积分";
        }
      },
      handleSizeChange3: function (pageSize) {
        this.pageRequest3.pageSize = pageSize;
        this.pageRequest3.pageNum = 1;
        let row = {'id' :this.rowId3}
        this.findPageDrawResult(row)

      },
      refreshPageRequest3: function (pageNum) {
        this.pageRequest3.pageNum = pageNum;
        let row = {'id' :this.rowId3}
        this.findPageDrawResult(row)
      },
    }
  }
</script>
<style scoped lang="scss">

</style>
